package com.szpx.mapper;

import com.szpx.entity.Goods;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author Wangtx
 * @version 1.0.0
 * @title GoodsMapper
 * @create 2024/4/6 22:22
 * @description
 */

public interface GoodsMapper extends Mapper<Goods> {
    /**
     * 浏览
     * @return
     */
    List<Goods> findAllGoods(@Param("id") Integer id);


    /**
     * 生成
     * @param goods
     */
    @Insert("INSERT INTO goods(id,name,weight,start_station,end_station,freight)" +
            "VALUES(#{id},#{name},#{weight},#{startStation},#{endStation},#{freight})")
    void addGoods(Goods goods);

    /**
     * 单个删除
     * @param id
     */
    @Delete("delete from goods where id=#{id}")
    void deleteGoodsByGoodsId(Integer id);

    /**
     * 批量删除
     * @param goodsIds
     */
    void deleteAllSelectGoods(List<Integer> goodsIds);
    /**
     * 修改
     * @param goods
     */
    @Update("UPDATE goods SET goods.name=#{name},goods.weight=#{weight},goods.start_station=#{startStation}," +
            "goods.end_station=#{endStation},goods.freight=#{freight} WHERE goods.id=#{id}")
    void updateGoods(Goods goods);

    /**
     * 计算
     * @param id
     * @return
     */
    @Select("SELECT freight*weight FROM goods WHERE goods.id=#{id}")
    Integer allFreightPrice(Integer id);

    @Select("SELECT * FROM goods")
    List<Goods> getGoodsList();
}
